﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Logistics_Service.DTO;

namespace Logistics_Service.DAO
{
    public class TinhThanhDAO
    {
        public TinhThanhDTO[] DanhSachTinhThanh()
        {
            TinhThanhDTO[] arr;
            string query = string.Format("select * from TinhThanh");
            DataProvider provider = new DataProvider();
            DataTable dt = provider.ExecuteQuery(query);
            int n = dt.Rows.Count;
            arr = new TinhThanhDTO[n];
            for (int i = 0; i < n; i++)
            {
                object td = GetDataFromDataRow(dt, i);
                arr[i] = (TinhThanhDTO)td;
            }
            return arr;
        }
        protected object GetDataFromDataRow(DataTable dt, int i)
        {
            TinhThanhDTO tt = new TinhThanhDTO();
            tt.Ma = dt.Rows[i]["Ma"].ToString();
            tt.Ten = dt.Rows[i]["Ten"].ToString();            
            tt.DaXoa = bool.Parse(dt.Rows[i]["DaXoa"].ToString());
            return (object)tt;
        }
        public static TinhThanhDTO Get(string matt)
        {
            TinhThanhDTO tt = new TinhThanhDTO();
            string query = "select * from TinhThanh where Ma = '"+matt+"'";
            DataProvider provider =  new DataProvider();
            DataTable dt = provider.ExecuteQuery(query);          
                        
            tt.Ma = matt;
            tt.Ten = dt.Rows[0]["Ten"].ToString();
            tt.DaXoa = bool.Parse(dt.Rows[0]["DaXoa"].ToString());                       

            return tt;
        }


       
    }
}